#ifdef HAVE_CONFIG_H
#        include <config.h>
#endif

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>

#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include "support.h"
#include "toolbar.h"
#include "clist.h"
#include "file.h"

#define GLADE_HOOKUP_OBJECT(component,widget,name) \
        g_object_set_data_full (G_OBJECT (component), name, \
                gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)

#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
        g_object_set_data (G_OBJECT (component), name, widget)
        
GtkWidget *create_toolbar(GtkWidget *window_main,
				GtkWidget *vbox_main,GtkTooltips *tooltips)
{
	/*-------this pointers used to make tool bar-------------------*/
        GtkWidget *toolbar;
        GtkIconSize tmp_toolbar_icon_size;
        
        GtkWidget *toolitem_new_info; /*item '新建'*/
        GtkWidget *button_new_info;
        GtkWidget *alignment_new;
        GtkWidget *hbox2;
        GtkWidget *image_new_info;
        GtkWidget *label_new_info;     
        GtkWidget *toolitem_new_vseparator;
        GtkWidget *vseparator_new;
        
        GtkWidget *toolitem_add_group; /*item '添加'*/
        GtkWidget *button_add_group;
        GtkWidget *alignment_add_group;
        GtkWidget *hbox3;
        GtkWidget *image_add_group;
        GtkWidget *label_add_group;     
        GtkWidget *toolitem_add_vseparator;
        GtkWidget *vseparator_add;
        
        GtkWidget *toolitem_save;/*item '保存'*/
        GtkWidget *button_save;
        GtkWidget *alignment_save;
        GtkWidget *hbox5;
        GtkWidget *image_save;
        GtkWidget *label_save;       
        GtkWidget *toolitem_save_vseparator;
        GtkWidget *vseparator_save;
 
        GtkWidget *toolitem_open_blog; /*item '打开'*/
        GtkWidget *button_open_blog;
        GtkWidget *alignment_open_blog;
        GtkWidget *hbox4;
        GtkWidget *image_open_blog;
        GtkWidget *label_open_blog;       
        GtkWidget *toolitem_open_vseparator;
        GtkWidget *vseparator_open;
        

	GtkWidget *toolitem_find_info; /*item '查找'*/
	GtkWidget *button_find_info;
	GtkWidget *alignment_find_info;
	GtkWidget *hbox7;	
	GtkWidget *image_find_info;
        GtkWidget *label_find_info;	
        GtkWidget *toolitem_find_vseparator;
        GtkWidget *vseparator_find;
        
        /*create widget toolbar*/
        toolbar = gtk_toolbar_new ();
        gtk_widget_show (toolbar);
        gtk_box_pack_start (GTK_BOX (vbox_main), toolbar, FALSE, FALSE, 0);
        gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH);
        gtk_toolbar_set_tooltips (GTK_TOOLBAR (toolbar), FALSE);
        tmp_toolbar_icon_size = gtk_toolbar_get_icon_size (GTK_TOOLBAR (toolbar));
	/*create toolitem '新建' for toolbar*/
        toolitem_new_info = (GtkWidget*) gtk_tool_item_new ();
        gtk_widget_show (toolitem_new_info);
        gtk_container_add (GTK_CONTAINER (toolbar), toolitem_new_info);
        gtk_container_set_border_width (GTK_CONTAINER (toolitem_new_info), 1);

        button_new_info = gtk_button_new ();
        gtk_widget_show (button_new_info);
        gtk_container_add (GTK_CONTAINER (toolitem_new_info), button_new_info);
        GTK_WIDGET_UNSET_FLAGS (button_new_info, GTK_CAN_FOCUS);
        gtk_tooltips_set_tip (tooltips, button_new_info, _("\346\226\260\345\273\272\344\270\200\344\270\252\344\277\241\346\201\257"), NULL);
        gtk_button_set_focus_on_click (GTK_BUTTON (button_new_info), FALSE);

        alignment_new = gtk_alignment_new (0.5, 0.5, 0, 0);
        gtk_widget_show (alignment_new);
        gtk_container_add (GTK_CONTAINER (button_new_info), alignment_new);

        hbox2 = gtk_vbox_new (FALSE, 2);
        gtk_widget_show (hbox2);
        gtk_container_add (GTK_CONTAINER (alignment_new), hbox2);

        image_new_info = gtk_image_new_from_stock ("gtk-new", GTK_ICON_SIZE_BUTTON);
        gtk_widget_show (image_new_info);
        gtk_box_pack_start (GTK_BOX (hbox2), image_new_info, FALSE, FALSE, 0);

        label_new_info = gtk_label_new_with_mnemonic (_("  \346\226\260\345\273\272  "));
        gtk_widget_show (label_new_info);
        gtk_box_pack_start (GTK_BOX (hbox2), label_new_info, FALSE, FALSE, 0);
        gtk_label_set_justify (GTK_LABEL (label_new_info), GTK_JUSTIFY_FILL);

        toolitem_new_vseparator = (GtkWidget*) gtk_tool_item_new ();
        gtk_widget_show (toolitem_new_vseparator);
        gtk_container_add (GTK_CONTAINER (toolbar), toolitem_new_vseparator);
        gtk_widget_set_sensitive (toolitem_new_vseparator, FALSE);

        vseparator_new = gtk_vseparator_new ();
        gtk_widget_show (vseparator_new);
        gtk_container_add (GTK_CONTAINER (toolitem_new_vseparator), vseparator_new);
        gtk_widget_set_sensitive (vseparator_new, FALSE);
	/*create toolitem '添加' for toolbar*/
        toolitem_add_group = (GtkWidget*) gtk_tool_item_new ();
        gtk_widget_show (toolitem_add_group);
        gtk_container_add (GTK_CONTAINER (toolbar), toolitem_add_group);

        button_add_group = gtk_button_new ();
        gtk_widget_show (button_add_group);
        gtk_container_add (GTK_CONTAINER (toolitem_add_group), button_add_group);
        GTK_WIDGET_UNSET_FLAGS (button_add_group, GTK_CAN_FOCUS);
        gtk_tooltips_set_tip (tooltips, button_add_group, _("\346\267\273\345\212\240\344\270\200\344\270\252\345\210\206\347\273\204"), NULL);

        alignment_add_group = gtk_alignment_new (0.5, 0.5, 0, 0);
        gtk_widget_show (alignment_add_group);
        gtk_container_add (GTK_CONTAINER (button_add_group), alignment_add_group);

        hbox3 = gtk_vbox_new (FALSE, 2);
        gtk_widget_show (hbox3);
        gtk_container_add (GTK_CONTAINER (alignment_add_group), hbox3);

        image_add_group = gtk_image_new_from_stock ("gtk-add", GTK_ICON_SIZE_BUTTON);
        gtk_widget_show (image_add_group);
        gtk_box_pack_start (GTK_BOX (hbox3), image_add_group, FALSE, FALSE, 0);

        label_add_group = gtk_label_new_with_mnemonic (_("  \346\267\273\345\212\240  "));
        gtk_widget_show (label_add_group);
        gtk_box_pack_start (GTK_BOX (hbox3), label_add_group, FALSE, FALSE, 0);

        toolitem_add_vseparator = (GtkWidget*) gtk_tool_item_new ();
        gtk_widget_show (toolitem_add_vseparator);
        gtk_container_add (GTK_CONTAINER (toolbar), toolitem_add_vseparator);
        gtk_widget_set_sensitive (toolitem_add_vseparator, FALSE);

        vseparator_add = gtk_vseparator_new ();
        gtk_widget_show (vseparator_add);
        gtk_container_add (GTK_CONTAINER (toolitem_add_vseparator), vseparator_add);
        gtk_widget_set_sensitive (vseparator_add, FALSE);
	/*create toolitem '保存' for toolbar*/
        toolitem_save = (GtkWidget*) gtk_tool_item_new ();
        gtk_widget_show (toolitem_save);
        gtk_container_add (GTK_CONTAINER (toolbar), toolitem_save);

        button_save = gtk_button_new ();
        gtk_widget_show (button_save);
        gtk_container_add (GTK_CONTAINER (toolitem_save), button_save);
        GTK_WIDGET_UNSET_FLAGS (button_save, GTK_CAN_FOCUS);
        gtk_tooltips_set_tip (tooltips, button_save, _("\344\277\235\345\255\230\344\277\256\346\224\271"), NULL);

        alignment_save = gtk_alignment_new (0.5, 0.5, 0, 0);
        gtk_widget_show (alignment_save);
        gtk_container_add (GTK_CONTAINER (button_save), alignment_save);

        hbox5 = gtk_vbox_new (FALSE, 2);
        gtk_widget_show (hbox5);
        gtk_container_add (GTK_CONTAINER (alignment_save), hbox5);

        image_save = gtk_image_new_from_stock ("gtk-save", GTK_ICON_SIZE_BUTTON);
        gtk_widget_show (image_save);
        gtk_box_pack_start (GTK_BOX (hbox5), image_save, FALSE, FALSE, 0);

        label_save = gtk_label_new (_("  \344\277\235\345\255\230  "));
        gtk_widget_show (label_save);
        gtk_box_pack_start (GTK_BOX (hbox5), label_save, FALSE, FALSE, 0);

        toolitem_save_vseparator = (GtkWidget*) gtk_tool_item_new ();
        gtk_widget_show (toolitem_save_vseparator);
        gtk_container_add (GTK_CONTAINER (toolbar), toolitem_save_vseparator);

        vseparator_save = gtk_vseparator_new ();
        gtk_widget_show (vseparator_save);
        gtk_container_add (GTK_CONTAINER (toolitem_save_vseparator), vseparator_save);
        gtk_widget_set_size_request (vseparator_save, 10, -1);
        gtk_widget_set_sensitive (vseparator_save, FALSE);
        
	/*create toolitem '打开' for toolbar*/
        toolitem_open_blog = (GtkWidget*) gtk_tool_item_new ();
        gtk_widget_show (toolitem_open_blog);
        gtk_container_add (GTK_CONTAINER (toolbar), toolitem_open_blog);

        button_open_blog = gtk_button_new ();
        gtk_widget_show (button_open_blog);
        gtk_container_add (GTK_CONTAINER (toolitem_open_blog), button_open_blog);
        GTK_WIDGET_UNSET_FLAGS (button_open_blog, GTK_CAN_FOCUS);
        gtk_tooltips_set_tip (tooltips, button_open_blog, _("\345\234\250firefox\344\270\255\346\211\223\345\274\200\345\215\232\345\256\242\351\223\276\346\216\245"), NULL);

        alignment_open_blog = gtk_alignment_new (0.5, 0.5, 0, 0);
        gtk_widget_show (alignment_open_blog);
        gtk_container_add (GTK_CONTAINER (button_open_blog), alignment_open_blog);

        hbox4 = gtk_vbox_new (FALSE, 2);
        gtk_widget_show (hbox4);
        gtk_container_add (GTK_CONTAINER (alignment_open_blog), hbox4);

        image_open_blog = gtk_image_new_from_stock ("gtk-indent", GTK_ICON_SIZE_BUTTON);
        gtk_widget_show (image_open_blog);
        gtk_box_pack_start (GTK_BOX (hbox4), image_open_blog, FALSE, FALSE, 0);

        label_open_blog = gtk_label_new_with_mnemonic (_("  \346\211\223\345\274\200  "));
        gtk_widget_show (label_open_blog);
        gtk_box_pack_start (GTK_BOX (hbox4), label_open_blog, FALSE, FALSE, 0);

        toolitem_open_vseparator = (GtkWidget*) gtk_tool_item_new ();
        gtk_widget_show (toolitem_open_vseparator);
        gtk_container_add (GTK_CONTAINER (toolbar), toolitem_open_vseparator);

        vseparator_open = gtk_vseparator_new ();
        gtk_widget_show (vseparator_open);
        gtk_container_add (GTK_CONTAINER (toolitem_open_vseparator), vseparator_open);
        gtk_widget_set_sensitive (vseparator_open, FALSE);
 
	/*create toolitem '查找' for toolbar*/
	toolitem_find_info = (GtkWidget*) gtk_tool_item_new ();
        gtk_widget_show (toolitem_find_info);
        gtk_container_add (GTK_CONTAINER (toolbar), toolitem_find_info);
	
        button_find_info = gtk_button_new ();
        gtk_widget_show (button_find_info);
        gtk_container_add (GTK_CONTAINER (toolitem_find_info), button_find_info);
        GTK_WIDGET_UNSET_FLAGS (button_find_info, GTK_CAN_FOCUS);
        gtk_tooltips_set_tip (tooltips, button_find_info, _("\346\237\245\346\211\276\344\270\200\344\270\252\344\277\241\346\201\257"), NULL);

        alignment_find_info = gtk_alignment_new (0.5, 0.5, 0, 0);
        gtk_widget_show (alignment_find_info);
        gtk_container_add (GTK_CONTAINER (button_find_info), alignment_find_info);
        hbox7 = gtk_vbox_new (FALSE, 2);
        gtk_widget_show (hbox7);
        gtk_container_add (GTK_CONTAINER (alignment_find_info), hbox7);

        image_find_info = gtk_image_new_from_stock ("gtk-find", GTK_ICON_SIZE_BUTTON);
        gtk_widget_show (image_find_info);
        gtk_box_pack_start (GTK_BOX (hbox7), image_find_info, FALSE, FALSE, 0);

        label_find_info = gtk_label_new (_("  \346\237\245\346\211\276  "));
        gtk_widget_show (label_find_info);
        gtk_box_pack_start (GTK_BOX (hbox7), label_find_info, FALSE, FALSE, 0); 
        
        toolitem_find_vseparator = (GtkWidget*) gtk_tool_item_new ();
        gtk_widget_show (toolitem_find_vseparator);
        gtk_container_add (GTK_CONTAINER (toolbar), toolitem_find_vseparator);

        vseparator_find = gtk_vseparator_new ();
        gtk_widget_show (vseparator_find);
        gtk_container_add (GTK_CONTAINER (toolitem_find_vseparator), vseparator_find);
        gtk_widget_set_size_request (vseparator_find, 10, -1);
        gtk_widget_set_sensitive (vseparator_find, FALSE);          
        
        g_signal_connect ((gpointer) button_new_info, "clicked",
                                                                                G_CALLBACK (on_button_new_info_clicked),
                                                                                NULL);
        g_signal_connect ((gpointer) button_add_group, "clicked",
                                                                                G_CALLBACK (on_button_new_group_clicked),
                                                                                NULL);
        g_signal_connect ((gpointer) button_save, "clicked",
                                                                                G_CALLBACK (on_button_save_clicked),
                                                                                (gpointer)&global_file);                                                                                                                   
        g_signal_connect ((gpointer) button_open_blog, "clicked",
                                                                                G_CALLBACK (on_button_open_blog_clicked),
                                                                                (gpointer)&clist);
        g_signal_connect ((gpointer) button_find_info, "clicked",
                                                                                G_CALLBACK (on_button_find_info_clicked),
                                                                                NULL);
       GLADE_HOOKUP_OBJECT (window_main, toolbar, "toolbar");
        GLADE_HOOKUP_OBJECT (window_main, toolitem_new_info, "toolitem_new_info");
        GLADE_HOOKUP_OBJECT (window_main, button_new_info, "button_new_info");
        GLADE_HOOKUP_OBJECT (window_main, alignment_new, "alignment_new");
        GLADE_HOOKUP_OBJECT (window_main, hbox2, "hbox2");
        GLADE_HOOKUP_OBJECT (window_main, image_new_info, "image_new_info");
        GLADE_HOOKUP_OBJECT (window_main, label_new_info, "label_new_info");
        GLADE_HOOKUP_OBJECT (window_main, toolitem_new_vseparator, "toolitem_new_vseparator");
        GLADE_HOOKUP_OBJECT (window_main, vseparator_new, "vseparator_new");
        GLADE_HOOKUP_OBJECT (window_main, toolitem_add_group, "toolitem_add_group");
        GLADE_HOOKUP_OBJECT (window_main, button_add_group, "button_add_group");
        GLADE_HOOKUP_OBJECT (window_main, alignment_add_group, "alignment_add_group");
        GLADE_HOOKUP_OBJECT (window_main, hbox3, "hbox3");
        GLADE_HOOKUP_OBJECT (window_main, image_add_group, "image_add_group");
        GLADE_HOOKUP_OBJECT (window_main, label_add_group, "label_add_group");
        GLADE_HOOKUP_OBJECT (window_main, toolitem_add_vseparator, "toolitem_add_vseparator");
        GLADE_HOOKUP_OBJECT (window_main, vseparator_add, "vseparator_add");
        GLADE_HOOKUP_OBJECT (window_main, toolitem_save, "toolitem_save");
        GLADE_HOOKUP_OBJECT (window_main, button_save, "button_save");
        GLADE_HOOKUP_OBJECT (window_main, alignment_save, "alignment_save");
        GLADE_HOOKUP_OBJECT (window_main, hbox5, "hbox5");
        GLADE_HOOKUP_OBJECT (window_main, image_save, "image_save");
        GLADE_HOOKUP_OBJECT (window_main, label_save, "label_save");
        GLADE_HOOKUP_OBJECT (window_main, toolitem_save_vseparator, "toolitem_save_vseparator");
        GLADE_HOOKUP_OBJECT (window_main, vseparator_save, "vseparator_save");
        GLADE_HOOKUP_OBJECT (window_main, toolitem_open_blog, "toolitem_open_blog");
        GLADE_HOOKUP_OBJECT (window_main, button_open_blog, "button_open_blog");
        GLADE_HOOKUP_OBJECT (window_main, alignment_open_blog, "alignment_open_blog");
        GLADE_HOOKUP_OBJECT (window_main, hbox4, "hbox4");
        GLADE_HOOKUP_OBJECT (window_main, image_open_blog, "image_open_blog");
        GLADE_HOOKUP_OBJECT (window_main, label_open_blog, "label_open_blog");
        GLADE_HOOKUP_OBJECT (window_main, toolitem_open_vseparator, "toolitem_open_vseparator");
        GLADE_HOOKUP_OBJECT (window_main, vseparator_open, "vseparator_open");
        /*---------------------------------------------------*/
         GLADE_HOOKUP_OBJECT (window_main, toolitem_find_info, "toolitem_find_info");
        GLADE_HOOKUP_OBJECT (window_main, button_find_info, "button_find_info");
        GLADE_HOOKUP_OBJECT (window_main, alignment_find_info, "alignment_find_info");
        GLADE_HOOKUP_OBJECT (window_main, hbox7, "hbox7");
        GLADE_HOOKUP_OBJECT (window_main, image_find_info, "image_find_info");
        GLADE_HOOKUP_OBJECT (window_main, label_find_info, "label_find_info");
        /*---------------------------------------------------*/
       
        return toolbar;
}
